package com.xyh.student.controller;

import com.xyh.student.entity.*;
import com.xyh.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/Student")
public class StudentController {

    @Autowired
    private StudentService studentS;

    //分页查询所有学生信息
    //http://localhost:8081/Student/queryAllStudents
    @GetMapping("/queryAllStudents")
    public ResponseData queryAllStudents(Integer pageNum, Integer pageSize){
        int start=(pageNum-1)*pageSize;
        return this.studentS.queryAllStudents(start,pageSize);
    }

    //根据名称目标学生的信息
    //http://localhost:8081/Student/queryByName
    @GetMapping("/queryByName")
    @ResponseBody
    public ResponseData queryByName(String name){
        return this.studentS.queryByName(name);
    }

    //http://localhost:8081/Student/queryBySid/{sid}
    @GetMapping("/queryBySid/{sid}")
    public ResponseData queryBySid(@PathVariable("sid") long sid){
        return this.studentS.queryBySid(sid);
    }

    //增加一个学生
    //http://localhost:8081/Student/insertStudent
    @PostMapping("/insertStudent")
    public ResponseData insertStudent(Student student){
        //System.out.println(student.toString());
        return this.studentS.insertStudent(student);
    }

    //更新数据
    //http://localhost:8081/Student/updateStudent
    @PostMapping("/updateStudent")
    public ResponseData updateStudent(@RequestBody Student student){
        return this.studentS.updateStudent(student);
    }

   // 通过sid删除目标学生的信息
   //http://localhost:8081/Student/deleteStudentBySid/{sid}
    @DeleteMapping("/deleteStudentBySid/{sid}")
    public ResponseData deleteStudentBySid(@PathVariable("sid") long sid){
        return this.studentS.deleteStudentBySid(sid);
    }

    //批量删除学生信息
    //http://localhost:8081/Student/deletes
    @DeleteMapping("deletes")
    public  ResponseData deletes(long[] sids){
        return this.studentS.deletes(sids);
    }

    //获得学生数量
    //http://localhost:8081/Student/numberOfStudents
    @GetMapping("/numberOfStudents")
    public ResponseData numberOfStudents(){
        return this.studentS.numberOfStudents();

    }

    //http://localhost:8081/Student/InsertStudentOfCourse
    // 通过学生输入的班级名称找到班级的cid并将其添加到学生表中
    @PostMapping("/InsertStudentOfCourse")
    public ResponseData InsertStudentOfCourse(@RequestBody Student student,String cname){
        return this.studentS.InsertStudentOfCourse(student,cname);
    }

    //http://localhost:8081/Student/queryCidByName
    // 通过学生输入的班级名称找到班级的cid
    @PostMapping("/queryCidByName")
    public ResponseData queryCidByName(String cname){
        return this.studentS.queryCidByName(cname);
    }


}
